package com.erclab.xbuilder.unitTests;

import static org.junit.Assert.fail;

import org.junit.Test;

import com.erclab.internal.xpresso.Application;
import com.erclab.internal.xpresso.exceptions.ApplicationException;
import com.erclab.xbuilder.db.MysqlDatabaseManager;
import com.erclab.xbuilder.db.TableColumn;
import com.erclab.xbuilder.exception.DBManagerException;

public class ApplicationTest {

	protected Application xbuilder;
	protected MysqlDatabaseManager mdm;

	public ApplicationTest(){
		this.startApplication();
	}
	
	public void startApplication(){
		try {
			xbuilder = new Application();
			System.out.println("Application created: " + xbuilder.getApplicationName());
			mdm = new MysqlDatabaseManager();
		} catch (ApplicationException e) {
			e.printStackTrace();
			fail();
		}
	}
	
	@Test
	public void createAddRemoveObject(){
		try {
			mdm.createTable("test_table", null);
			mdm.alterTable("test_table", "ADD test_field VARCHAR(100)");
			mdm.addColumnToTable("test_table", new TableColumn("test_column", "VARCHAR(100)"));
			mdm.dropColumn("test_table", new TableColumn("test_column", null));
			mdm.dropTable("test_table");
		} catch (DBManagerException e) {
			e.getTheException().printStackTrace();
			fail();
		}
	}
	
	
	
}
